package cate.game.chat;

import cate.game.util.api.ChatApi;
import cp.external.yzx.speech.YzxSpeechOutput;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcException;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class ChatRequest {

    @NoteField(value = "频道", detail = "枚举值见在线文档GDChat.Channel.XXX")
    public byte channel;

    @NoteField(value = "消息内容ID")
    public int contentId;

    @NoteField(value = "消息内容")
    public String content;

    @NoteField(value = "内容参数")
    public List<ChatContentParam> params;

    public static void checkSign(String content, String checkSignFromClient) {
        if(!ChatApi.CLIENT_DRIVE_MODE) {
            return;
        }
        if (StringUtils.isBlank(checkSignFromClient)) {
            throw new EcException("checkSign is Blank");
        }
        String correctSign = YzxSpeechOutput.makeSign(content);
        if(!StringUtils.equals(correctSign, checkSignFromClient)) {
            throw new EcException("check illegal");
        }
    }
}
